package com.zfxt.biz.autoconfig;

import com.zfxt.common.RestResponse;
import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2018/9/11.
 */
@Service
public class GenericRest {

    @Autowired
    private RestTemplate restTemplate;                              //支持反序列化包装类型的一个类
    public <T> ResponseEntity<T> post(String url , Object reqBody , ParameterizedTypeReference<T> responseType  ){
        RestTemplate restTemplate=getRestTemplate(url);
        return restTemplate.exchange(url, HttpMethod.POST,new HttpEntity(reqBody),responseType);
    }
    public <T> ResponseEntity<T> get(String url ,  ParameterizedTypeReference<T> responseType  ){
        RestTemplate restTemplate=getRestTemplate(url);
        return restTemplate.exchange(url, HttpMethod.GET,HttpEntity.EMPTY,responseType);
    }
    private RestTemplate getRestTemplate(String url){
        return restTemplate;
    }

}
